package com.yiwei.zhh.api.requestInfo;

import com.yiwei.zhh.api.Api;
import com.yiwei.zhh.api.bean.MessageBean;
import com.yiwei.zhh.api.callback.MessageContract;
import com.yiwei.zhh.util.Network;
import com.yiwei.zhh.util.RxLifeUtil;
import com.yiwei.zhh.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class MessageRequest extends BaseRequest<MessageContract.View> implements MessageContract.Presenter<MessageContract.View> {

    public static MessageRequest create() {
        return new MessageRequest();
    }


    @Override
    public void getMessageInfo(int type, int pageIndex) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        MessageBean bean = new MessageBean();
        bean.page = pageIndex+"";
        Api.api_service.getMessageInfo(bean).compose(RxLifeUtil.NocheckOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getMessageInfoSuccess(type,pageIndex,result);
                });
    }
}
